<template>
  <el-dialog
      v-model="itemsEditWinDialog"
      title="编辑台账"
      width="50%">
    <template #default>
      <el-form :model="editItem" label-width="auto">
        <el-form-item label="项目编码">
          <el-input v-model="editItem.projectCode"/>
        </el-form-item>
        <el-form-item label="项目名称">
          <el-input v-model="editItem.projectName"/>
        </el-form-item>
<!--        <el-form-item label="项目类型">-->
<!--          <el-input v-model="editItem.projectType"/>-->
<!--        </el-form-item>-->
        <el-form-item label="项目类型">
          <el-radio-group v-model="editItem.projectType">
            <el-radio value="设备检点" size="large">设备检点</el-radio>
            <el-radio value="设备保养" size="large">设备保养</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="项目内容">
          <el-input v-model="editItem.projectContent"/>
        </el-form-item>
        <el-form-item label="项目标准">
          <el-input v-model="editItem.projectStandard"/>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-select style="width: 100px" v-model="editItem.projectStatus">
            <el-option :value="1" label="启用"/>
            <el-option :value="2" label="禁用"/>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="editItem.projectNotes"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="editItemSubmit">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>

import {ref, watch} from "vue";
import ledgerRequest from "@/api/ledger.js";
import {ElMessage} from "element-plus";
import maintainItemsRequest from "@/api/maintainItems.js";
const props = defineProps(['projectId']);
const emits = defineEmits(['editComplate']);
let itemsEditWinDialog = ref(false);
let editItem = ref({});

function cancel(){
  editItem = ref({});
  itemsEditWinDialog.value =false;
}
function editItemSubmit(){
  maintainItemsRequest.updateItems(editItem.value,res=>{
    if (res.code == 200){
      ElMessage({
        type:"success",
        message:"修改成功"
      });
      cancel()
      emits('editComplate');
    }else {
      ElMessage({
        type:"warning",
        message:"修改失败"
      })
    }
  })
}

function loadItemById(){
  maintainItemsRequest.selectById(props.projectId,res=>{
    if (res.data){
      editItem.value =res.data;
      itemsEditWinDialog.value = true;
    }
  })
}

watch(()=>props.projectId,()=>{
  if(props.projectId){
    loadItemById();
  }
});


</script>

<style scoped>

</style>